package ch01_iterator;

public class Main {
    public static void main(String[] args) {
        Iterator<Book> it = getBookShelfIterator();
        showBooks(it);
        System.out.println("---------------------------------------------------");
        it = getBookShelfIterator2();
        showBooks(it);
        System.out.println("---------------------------------------------------");
        it = getArrayListBookShelfIterator();
        showBooks(it);
    }

    private static BookShelf getBookShelf() {
        BookShelf bookShelf = new BookShelf(4);
        bookShelf.appendBook(new Book("Around the World in 80 Days"));
        bookShelf.appendBook(new Book("Bible"));
        bookShelf.appendBook(new Book("Cinderella"));
        bookShelf.appendBook(new Book("Daddy-Long-Legs"));
        return bookShelf;
    }

    private static Iterator<Book> getBookShelfIterator() {
        return getBookShelf().iterator();
    }

    private static Iterator<Book> getBookShelfIterator2() {
        return getBookShelf().iterator2();
    }

    private static Iterator<Book> getArrayListBookShelfIterator() {
        ArrayListBookShelf bookShelf = new ArrayListBookShelf();
        bookShelf.appendBook(new Book("Around the World in 80 Days"));
        bookShelf.appendBook(new Book("Bible"));
        bookShelf.appendBook(new Book("Cinderella"));
        bookShelf.appendBook(new Book("Daddy-Long-Legs"));
        bookShelf.appendBook(new Book("图解设计模式"));
        return bookShelf.iterator();
    }

    private static void showBooks(Iterator<Book> it) {
        while (it.hasNext()) {
            System.out.println(it.next().getName());
        }
    }
}
